package com.app.toknow.View;

import android.app.Dialog;
import android.content.Context;
import android.widget.TextView;

import com.app.toknow.R;


/**
 * Created by kangw on 2015/10/3.
 */
    public class CustomProgressDialog extends Dialog  {

        private boolean isCancelable = false;

        public CustomProgressDialog(Context context) {
            super(context);
        }
        public CustomProgressDialog(Context context, String strMessage) {
            this(context, R.style.LoadingDialogStyle, strMessage);
        }

    public CustomProgressDialog(Context context, int theme, String strMessage) {
        super(context, theme);
        this.setContentView(R.layout.loading_dialog);
        TextView tvMsg = (TextView) this.findViewById(R.id.progressStrMessage);
        if (tvMsg != null) {
            tvMsg.setText(strMessage);
        }
    }
    @Override
    public void onWindowFocusChanged(boolean hasFocus) {

        if (!hasFocus&& !isCancelable) {
            dismiss();
        }
    }

    @Override
    public void setCancelable(boolean flag) {
        super.setCancelable(flag);
        isCancelable = flag;
    }
}
